
module.exports = {
    MD5_SUFIXX: '#$%^&*()fghrthjmvjoo)&#xyjk<>>:k',
    md5: function (str) {
        const crypto = require('crypto');
        var obj = crypto.createHash('md5');
        obj.update(str + this.MD5_SUFIXX);
        return obj.digest('hex')
    },
    db: function () {
        const mysql = require('mysql');
        var db = mysql.createConnection({
            host: 'localhost',
            user: 'root',
            password: 'root',
            port: 3306,
            database: 'blog'
        });
        return db;
    },
    uploder: function (req,res) {
        const fs = require('fs');
        const pathLib = require('path');
        //获取原始的文件名
        var originalname = req.files[0].originalname;
        //获取文件的扩展名称
        var extname = pathLib.parse(originalname).ext;
        //组合新的文件名称
        var newname = req.files[0].path + extname;
        console.log(  );
        fs.rename(req.files[0].path, newname, (err) => {
            if (err) {
                console.log('重命名失败');
                return;
            }else{
                console.log( {"path":newname} );
            }
        });
        return {"path":newname};
    }
};